package com.lego.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lego.service.OrdersService;
import com.lego.service.impl.OrdersServiceImpl;

/**后台数据概览数据
 * Servlet implementation class SelectOverviewServlet
 */
@WebServlet("/selectOverview.do")
public class SelectOverviewServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		OrdersService os = new OrdersServiceImpl();
		request.setCharacterEncoding("utf-8");
		//今日订单数量
		int todayOrders = os.selectTodayOrders();
		//总的订单数量
		int allOrders = os.selectUserRows("", 0);
		//今日销售额
		double todaAmount = os.selectTodayAmoun();
		//总销售额
		double allAmount = os.selectAllAmount();
		//六个模块分开的数据
		double[] data = os.selectEveryCard();
		data[6] = todayOrders;
		data[7] = allOrders;
		data[8] = todaAmount;
		data[9] = allAmount;
		//创建一个数组转换成json字符串返回给前端
		ObjectMapper om = new ObjectMapper();
		String str = om.writeValueAsString(data);
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(str);
	}

}
